<!-- 菜品估清-清空已选菜品估清售罄菜品-清空所有菜品估清售罄菜品-弹窗组件 -->
<template>
  <div>
    <CustomDialog v-model:visible="isShowDialog">
      <div class="dialog-content">
        <div class="title" v-if="actionType === 'all'">清空全部估清</div>
        <div class="title" v-else>清空已选菜品估清</div>
        <div class="description" v-if="actionType === 'all'">您确定清空全部估清吗？</div>
        <div class="description" v-else>您确定清空已选菜品估清吗？</div>
        <div class="btn-box">
          <el-button class="cancel-btn" @click="onCancel" :disabled="loading">取消</el-button>
          <el-button class="confirm-btn" type="primary" @click="onConfirm" :loading="loading"
            >确定</el-button
          >
        </div>
      </div>
    </CustomDialog>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import CustomDialog from '@/components/CustomDialog/Index.vue'

interface Props {
  // 是否显示弹窗
  showDialog: boolean
  // 区分全部菜品估清(all)还是选中对应菜品(current)进行估清
  actionType: string // all是全部估清，current是选中菜品的估清
}

const props = defineProps<Props>()
const emit = defineEmits(['update:showDialog', 'onConfirm'])

// loading状态
const loading = ref(false)

const isShowDialog = computed({
  get() {
    return props.showDialog
  },
  set(val) {
    emit('update:showDialog', val)
  }
})

// 取消事件
const onCancel = () => {
  if (loading.value) return
  emit('update:showDialog', false)
}

// 确认提交事件
const onConfirm = async () => {
  if (loading.value) return

  loading.value = true
  try {
    emit('onConfirm')
    // 接口调用成功后会自动关闭弹窗，这里不需要手动关闭
  } catch (error) {
    console.error('确认操作失败:', error)
  } finally {
    loading.value = false
  }
}
</script>

<style lang="scss" scoped>
.dialog-content {
  .title {
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
  }
  .description {
    margin-top: 70px;
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    color: #353535;
  }
  .btn-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 95px;
    .cancel-btn {
      width: 190px;
      height: 60px;
      background: #ffffff;
      border: 1px solid #333333;
      border-radius: 12px;
      font-size: 18px;
      font-family:
        PingFang SC,
        PingFang SC-Regular;
      font-weight: 400;
      text-align: center;
      color: #333333;
      line-height: 60px;
      cursor: pointer;
    }
    .confirm-btn {
      width: 190px;
      height: 60px;
      background: #7c0a03;
      border-radius: 12px;
      font-size: 18px;
      font-family:
        PingFang SC,
        PingFang SC-Regular;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
      line-height: 60px;
      cursor: pointer;
    }
  }
}
</style>
